// Copyright © 1994 Apple Computer, Inc. All rights reserved.

constant kAppSymbol := '|TrueGrid:PIEDTS|;
constant kAppObject := '["Record", "Records"];
constant kSoupName := "TrueGrid:PIEDTS";
DefConst('kSoupIndexes, '[{structure: slot, path: aString, type: string}]);

constant kSoupPad := 256;	// bytes of "undisplayed" data in the soup.

constant kNumbersList := '["1", "5", "10", "25", "50", "100"];
constant kNumbersArray := '[1, 5, 10, 25, 50, 100];

// for tracking hilite in drawn rows
DefConst('kXORstyle, {penPattern: vfNone, transferMode: modeXor, fillPattern: vfBlack});

// for drawn row.
DefConst('kLeftTextStyle, {font: ROM_fontSystem9, penSize: 1, penPattern: vfBlack, justification: 'left});
DefConst('kCenterTextStyle, {font: ROM_fontSystem9, penSize: 1, penPattern: vfBlack, justification: 'center});
DefConst('kRightTextStyle, {font: ROM_fontSystem9, penSize: 1, penPattern: vfBlack, justification: 'right});
DefConst('kBorderStyle, {penPattern: vfGray});


// ---- End Project Data ----


// ---- File True Grid.t ----

// Before Script for "TrueGrid"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

TrueGrid :=
   {
    gridList:
      [
      "None",
      "Columns",
      "Cached Columns",
      "Draw Rows",
      "Cached Draw Rows",
      "Simple Rows",
      ],
    viewSetupDoneScript:
      func()
      begin
         theSoup :=  call kRegisterCardSoupFunc with (kSoupName, kSoupIndexes, kAppSymbol, kAppObject);
         theCursor := Query(theSoup, {type: 'index, indexPath: 'aString});
      
         viewsList := [columns, cachedColumns, drawRows, cachedDrawRows, simpleRows];
         gc();
         baseMemory := stats();
         :SoupChanged(kSoupName);
      end,
    viewFormat: nil,
    theSoup: nil,
    viewQuitScript:
      func()
      begin
         call kUnRegisterCardSoupFunc with (kSoupName);
      	theCursor := nil;
      	theSoup := nil;
      	viewsList := nil;
      	theGrid := nil;
      end,
    baseMemory: nil,
    viewFlags: 7,
    viewsLIst: nil,
    viewBounds: {left: 0, top: 0, right: 240, bottom: 336},
    FillSoup:
      func(theSoup, items)
      begin
         local i;
         for i := 1 to items do
            theSoup:AddToDefaultStore({
               aString: GetRandomWord(5,20) & $- & GetRandomWord(5,20),
               anInteger: Random(0,10000),
               aDate: Time() + Random(-14400,14400),
               pad: SetLength(SetClass(Clone(""), 'binary), kSoupPad),
            });
      end,
    theCursor: nil,
    DestroySoup:
      func()
      begin
         local store, mySoup;
      
         // remove the soup from each store currently installed
         foreach store in GetStores() do
            if mySoup := store:GetSoup(soupName) then
               mySoup:RemoveFromStore();
      end,
    viewScrollDownScript:
      func()
      begin
         if theGrid then begin
      		local t1 := ticks();
      		theGrid:viewScrollDownScript();
      		local t2 := ticks(); 
      		RefreshViews();
      		local t3 := ticks();
      		SetValue(theTimeDisplay, 'text, "Scrolling took " & t2-t1 & "+" & t3-t2 & "=" & t3-t1 & " ticks.");
      		gc();
      		SetValue(theMemoryDisplay, 'text, "Using " & baseMemory-stats() & " bytes.");
         end;
      	else
      		:SysBeep();
      end ,
    title: "True Grid",
    viewScrollUpScript:
      func()
      begin
         if theGrid then begin
      		local t1 := ticks();
      		theGrid:viewScrollUpScript();
      		local t2 := ticks(); 
      		RefreshViews();
      		local t3 := ticks();
      		SetValue(theTimeDisplay, 'text, "Scrolling took " & t2-t1 & "+" & t3-t2 & "=" & t3-t1 & " ticks.");
      		gc();
      		SetValue(theMemoryDisplay, 'text, "Using " & baseMemory-stats() & " bytes.");
      	end
         else
      		:SysBeep();
      end,
    EmptySoup:
      func(theSoup, items)
      begin
         local c := Query(theSoup, {type: 'index});
         for i := 1 to items do begin
            if c:Entry() then EntryRemoveFromSoup(c:Entry());
      	    	c:Next();
      	  end;
      end,
    declareSelf: 'base,
    theGrid: nil,
    viewclass: 74,
    debug: "TrueGrid",
    soupChanged:
      func(theSoupName)
      begin
      	theCursor:Reset();
      	local l := Length(MapCursor(theCursor, func(x) true));
      	SetValue(theCountDisplay, 'text, l && "soup entries");
      	RefreshViews();
      	local t1 := ticks();
      	theGrid:?soupChanged(theSoupName);
      	RefreshViews();
      	local t2 := ticks(); 
      	RefreshViews();
      	local t3 := ticks();
      	SetValue(theTimeDisplay, 'text, "Updating took " & t2-t1 & "+" & t3-t2 & "=" & t3-t1 & " ticks.");
      	gc();
      	SetValue(theMemoryDisplay, 'text, "Using " & baseMemory-stats() & " bytes.");
      end,
    EntrySelected:
      func(entry)
      begin
         SetValue(tappedOn, 'text, "Tapped On: " & if entry then entry.aString else "<none>");
         tappedOn:Open();
         RefreshViews();
         sleep(60);
         tappedOn:Close();
      end
   };

theTitle := /* child of TrueGrid */
   {title: "True Grid", _proto: protoTitle, debug: "theTitle"};
// View theTitle is declared to TrueGrid



_view000 := /* child of TrueGrid */ {_proto: protoStatusBar};

_view001 := /* child of _view000 */
   {viewBounds: {top: -16, left: -19, right: -6, bottom: -3},
    _proto: protoLargeClosebox
   };



RemoveButton := /* child of _view000 */
   {text: "Remove",
    viewBounds: {top: 2, left: -50, right: -6, bottom: 15},
    pickActionScript:
      func(item)
      begin
      	:EmptySoup(theSoup, kNumbersArray[item]);
      	:SoupChanged(kSoupName);
      	:Hilite(nil) ;
      end,
    viewJustify: 8390662,
    pickCancelledScript:
      func()
      begin
      	:Hilite(nil);
      end,
    viewClickScript:
      func(unit)
      begin
      // need to use a viewClickScript to get the correct
      // hiliting behavior for a picker
      	if :TrackHilite(unit) then
      	begin
      		local l := :LocalBox() ;
      	   DoPopup(kNumbersList, l.right+3, l.top, self);
      	end;
      
      end,
    _proto: protoTextButton,
    debug: "RemoveButton"
   };



AddButton := /* child of _view000 */
   {text: "Add",
    viewBounds: {top: 2, left: -38, right: -6, bottom: 15},
    pickActionScript:
      func(item)
      begin
      	:FillSoup(theSoup, kNumbersArray[item]);
      	:SoupChanged(kSoupName);
      	:Hilite(nil) ;
      end,
    viewJustify: 8390662,
    pickCancelledScript:
      func()
      begin
      	:Hilite(nil);
      end,
    viewClickScript:
      func(unit)
      begin
      // need to use a viewClickScript to get the correct
      // hiliting behavior for a picker
      	if :TrackHilite(unit) then
      	begin
      		local l := :LocalBox() ;
      	   DoPopup(kNumbersList, l.right+3, l.top, self);
      	end;
      
      end,
    _proto: protoTextButton,
    debug: "AddButton"
   };



ChooseButton := /* child of _view000 */
   {viewBounds: {left: 25, top: 2, right: 85, bottom: 15},
    pickActionScript:
      func(item)
      begin
      	// maintain state for the checkmark in the pick list
      	selected := item ;
      	
         if item = 0 then begin
         	theTitle:Close();
         	SetValue(theTitle, 'title, "True Grid");
         	theTitle:Open();
            theGrid:?Close();
         end;
         else if item <= length(viewsList) then begin
            theGrid:?Close();
         	theTitle:Close();
            SetValue(theTitle, 'title, gridList[item]);
         	theTitle:Open();
            RefreshViews();
         	gc();
         	baseMemory := stats();
            theGrid := viewsList[item-1];
            local t1 := ticks();
            theGrid:Open();
            local t2 := ticks();
            RefreshViews();
            local t3 := ticks();
      		SetValue(theTimeDisplay, 'text, "Opening took " & t2-t1 & "+" & t3-t2 & "=" & t3-t1 & " ticks.");
      		gc();
      		SetValue(theMemoryDisplay, 'text, "Using " & baseMemory-stats() & " bytes.");
         end;
         // unhilite the button
         :Hilite(nil) ;
      
      end,
    selected: 0,
    viewClickScript:
      func(unit)
      begin
      // need to use a viewClickScript to get the correct
      // hiliting behavior for a picker
      	if :TrackHilite(unit) then
      	begin
      		local l := :LocalBox() ;
      		local popList := Clone(gridList);
      		popList[selected] := {item: popList[selected], mark: kCheckMarkChar};
      	   DoPopup(popList, l.right+3, l.top, self);
      	end;
      
      end,
    pickCancelledScript:
      func()
      begin
      	:Hilite(nil);
      end,
    _proto: protoTextButton,
    debug: "ChooseButton"
   };

// After Script for "ChooseButton"
thisView := ChooseButton;
// set the bounds of the button so that it is to the right
// of the clock and the correct height for the status bar

// NOTE: this is the first button, so argument to the
// ButtonBounds function MUST be negative
thisView.viewBounds := ButtonBounds(-(thisView.viewBounds.right - thisView.viewBounds.left));

// set the text to have the pop diamond
thisView.text := kPopChar && "Choose" ;





theTimeDisplay := /* child of TrueGrid */
   {text: "timing",
    viewBounds: {left: 0, top: 18, right: 186, bottom: 30},
    viewJustify: 8388626
    ,
    _proto: protoStaticText,
    debug: "theTimeDisplay"
   };
// View theTimeDisplay is declared to TrueGrid



theMemoryDisplay := /* child of TrueGrid */
   {text: "Tapped On: <none>",
    viewBounds: {left: 0, top: 0, right: 186, bottom: 12},
    viewJustify: 8396818,
    _proto: protoStaticText,
    debug: "theMemoryDisplay"
   };
// View theMemoryDisplay is declared to TrueGrid



theCountDisplay := /* child of TrueGrid */
   {text: "Static Text",
    viewBounds: {left: 0, top: 0, right: 186, bottom: 12},
    viewJustify: 8396818,
    _proto: protoStaticText,
    debug: "theCountDisplay"
   };
// View theCountDisplay is declared to TrueGrid



// ---- File Columns.t ----

// Before Script for "columns"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

columns := /* child of TrueGrid */
   {myCursor: nil,
    viewSetupDoneScript:
      func()
      begin
      	visibleRows := :LocalBox().bottom DIV viewLineSpacing + 1;
      	myCursor := theCursor:Clone();
      	myCursor:Reset();
      	topEntry := myCursor:Entry();
         :FillCache();
      end,
    viewFormat: 337,
    viewlinespacing: 13,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    integerCache: nil,
    stringCache: nil,
    viewFlags: 544,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local stringLen := 0;
      	local integerLen := 0;
      	local dateLen := 0;
         local stringCache := SmartStart(128);
         local integerCache :=  SmartStart(128);
      	local dateCache :=  SmartStart(128);
      	local entry := topEntry;
      
      	keyArray := Array(visibleRows, nil);
         if entry then
      	   begin
      		   myCursor:Goto(topEntry);
      		   for i := 0 to visibleRows-1 do
      		      begin
      					stringLen := SmartConcat(stringCache, stringLen, entry.aString);
      					stringLen := SmartConcat(stringCache, stringLen, $\n);
      					integerLen := SmartConcat(integerCache, integerLen, SPrintObject(entry.anInteger));
      					integerLen := SmartConcat(integerCache, integerLen, $\n);
      					dateLen := SmartConcat(dateCache, dateLen, ShortDateStr(entry.aDate, kIncludeAllElements));
      					dateLen := SmartConcat(dateCache, dateLen, $\n);
      					keyArray[i] := entry.aString;
      					if not entry := myCursor:Next() then begin
      						SetLength(keyArray, i+1);
      						break;
      					end;
      				end;
      		end;
      	else
      		SetLength(keyArray, 0) ;
      		
         SmartStop(stringCache, stringLen);
         SmartStop(integerCache, integerLen);
         SmartStop(dateCache, dateLen);
         SetValue(stringCol, 'text, stringCache);
         SetValue(integerCol, 'text, integerCache);
         SetValue(dateCol, 'text, dateCache);
      end,
    viewOriginY: 0,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Goto(topEntry);
      	if not topEntry := myCursor:Move(visibleRows - 2) then
      		if not topEntry := myCursor:Move(2 - visibleRows) then
      			topEntry := myCursor:Next();
      	:fillCache();
      end,
    viewJustify: 208,
    topEntry: nil,
    visibleRows: nil,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Goto(topEntry);
      	if not topEntry := myCursor:Move(2 - visibleRows) then
      		topEntry := myCursor:Next();
      	:fillCache();
      end,
    keyArray: nil,
    viewClickScript:
      func(unit)
      begin
         InkOff(unit);
         PlaySound(ROM_click);
         local box := :LocalBox();
         local row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         local theRow := row;
         local inside := true;
         local t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
         :DoDrawing('DrawShape, [t, kXORstyle]);
         repeat
            row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
            if inside and row <> theRow then begin
               :DoDrawing('DrawShape, [t, kXORstyle]);
               inside := nil;
            end;
      		else if not inside and row = theRow then begin
      			:DoDrawing('DrawShape, [t, kXORstyle]);
      			inside := true;
      		end;	
            sleep(1);
         until StrokeDone(unit);
       
         row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         if row = theRow and row < length(keyArray) then 
            :EntrySelected(myCursor:GotoKey(keyArray[row]));
         else
            :EntrySelected(nil);
         if inside then
         	begin	// simply XOring the rectangle again won't work, :EntrySelected() changes drawing.
         		:Dirty();
         		RefreshViews();
         	end
      end;,
    viewclass: 74,
    debug: "columns",
    dateCache: nil,
    soupChanged:
      func(theSoupName)
      	if StrEqual(theSoupName, kSoupName) then begin
      		topEntry := myCursor:Reset();
      	   :FillCache();
      end
   };
// View columns is declared to TrueGrid

stringCol := /* child of columns */
   {viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {left: 0, top: 0, right: 300, bottom: 1000},
    viewFlags: 134217731,
    viewlinespacing: 13,
    viewclass: 81,
    debug: "stringCol"
   };
// View stringCol is declared to columns



dateCol := /* child of columns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewBounds: {top: 0, left: -60, right: 0, bottom: 1000},
    viewFont: ROM_fontSystem9;,
    viewlinespacing: 13,
    viewJustify: 34,
    viewclass: 81,
    debug: "dateCol"
   };
// View dateCol is declared to columns



integerCol := /* child of columns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {top: 0, left: -40, right: 0, bottom: 1000},
    viewlinespacing: 13
    ,
    viewJustify: 2049,
    viewclass: 81,
    debug: "integerCol"
   };
// View integerCol is declared to columns




// ---- Back in File True Grid.t ----

// ---- File Cached Columns.t ----

// Before Script for "cachedColumns"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

cachedColumns := /* child of TrueGrid */
   {viewFlags: 544,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local stringLen := 0;
      	local integerLen := 0;
      	local dateLen := 0;
         local stringCache := SmartStart(128);
         local integerCache :=  SmartStart(128);
      	local dateCache :=  SmartStart(128);
      
         local f := func(entry)
            begin
      			stringLen := SmartConcat(stringCache, stringLen, entry.aString);
      			stringLen := SmartConcat(stringCache, stringLen, $\n);
      			integerLen := SmartConcat(integerCache, integerLen, SPrintObject(entry.anInteger));
      			integerLen := SmartConcat(integerCache, integerLen, $\n);
      			dateLen := SmartConcat(dateCache, dateLen, ShortDateStr(entry.aDate, kIncludeAllElements));
      			dateLen := SmartConcat(dateCache, dateLen, $\n);
      			entry.aString;
            end;
      
         myCursor:Reset();
         keyArray := MapCursor(myCursor, f);
         SmartStop(stringCache, stringLen);
         SmartStop(integerCache, integerLen);
         SmartStop(dateCache, dateLen);
         SetValue(stringCol, 'text, stringCache);
         SetValue(integerCol, 'text, integerCache);
         SetValue(dateCol, 'text, dateCache);
      end,
    keyArray: nil,
    viewOriginY: 0,
    viewScrollUpScript:
      func()
      begin
         :SetOrigin(0, MAX(viewOriginY - scrollIncrement, 0));
      end,
    viewScrollDownScript:
      func()
      begin
         :SetOrigin(0, viewOriginY + scrollIncrement);
      end,
    viewlinespacing: 13,
    viewSetupDoneScript:
      func()
      begin
      	scrollIncrement := (:LocalBox().bottom DIV viewLineSpacing - 1) * viewLineSpacing;
         :SetOrigin(0,0);
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         :SetOrigin(0,0);
         :FillCache();
      end,
    viewClickScript:
      func(unit)
      begin
         InkOff(unit);
         PlaySound(ROM_click);
         local box := :LocalBox();
         local row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         local oldRow := row;
         local t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
         :DoDrawing('DrawShape, [t, kXORstyle]);
         repeat
            row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
            if row <> oldRow then begin
               PlaySound(ROM_click);
               :DoDrawing('DrawShape, [t, kXORstyle]);
               t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
               :DoDrawing('DrawShape, [t, kXORstyle]);
               oldRow := row;
            end;
            sleep(1);
         until StrokeDone(unit);
       
         row := (GetPoint(finalY, unit) - :GlobalBox().top + viewOriginY) div viewLineSpacing;
         if row < length(keyArray) then 
            :EntrySelected(myCursor:GotoKey(keyArray[row]));
         else
            :EntrySelected(nil);
         :DoDrawing('DrawShape, [t, kXORstyle]);
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    myCursor: nil,
    scrollIncrement: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "cachedColumns"
   };
// View cachedColumns is declared to TrueGrid

stringCol := /* child of cachedColumns */
   {viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {left: 0, top: 0, right: 300, bottom: 1000},
    viewFlags: 134217731,
    viewlinespacing: 13,
    viewclass: 81,
    debug: "stringCol"
   };
// View stringCol is declared to cachedColumns



dateCol := /* child of cachedColumns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewBounds: {top: 0, left: -60, right: 0, bottom: 1000},
    viewFont: ROM_fontSystem9;,
    viewlinespacing: 13,
    viewJustify: 34,
    viewclass: 81,
    debug: "dateCol"
   };
// View dateCol is declared to cachedColumns



integerCol := /* child of cachedColumns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {top: 0, left: -40, right: 0, bottom: 1000},
    viewlinespacing: 13
    ,
    viewJustify: 2049,
    viewclass: 81,
    debug: "integerCol"
   };
// View integerCol is declared to cachedColumns




// ---- Back in File True Grid.t ----

// ---- File Draw Rows.t ----

// Before Script for "drawRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

drawRows := /* child of TrueGrid */
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
         local fillCursor := myCursor:Clone();
         for i := 0 to numChildren-1 do begin
            :ChildViewFrames()[i]:UpdateFromSoup(fillCursor:Entry());
            fillCursor:Next();
         end;
      	:Dirty();
      end,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Move(2 - numChildren);
      	if not myCursor:Entry() then myCursor:Next();
      	:FillCache();
      end,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Move(numChildren-2);
      	:FillCache();
      end,
    viewSetupDoneScript:
      func()
      begin
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
      end,
    viewClickScript:
      
      func(unit)
      begin
      
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
         numChildren := :LocalBox().bottom DIV 13 + 1;
         self.stepChildren := Array(numChildren, pt_protoDrawnRow);
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "drawRows"
   };
// View drawRows is declared to TrueGrid


// ---- Back in File True Grid.t ----

// ---- File Cached Draw Rows.t ----

// Before Script for "cachedDrawRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

cachedDrawRows := /* child of TrueGrid */
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local childTemplate;
      	local visibleChildren := :LocalBox().bottom DIV viewLineSpacing + 1;
      	
         local f := func(entry)
            begin
            	childTemplate := {_proto: pt_protoDrawnRow};
            	childTemplate:UpdateFromSoup(entry);
            	AddArraySlot(stepChildren, childTemplate); 
      			entry.aString;
            end;
      	
      	stepChildren := [];
      	myCursor:Reset();
      	keyArray := MapCursor(myCursor, f);
      	numChildren := length(keyArray);
      	maxScrollHeight := MAX(0, numChildren - visibleChildren + 2) * viewLineSpacing;
      	for i := 0 to MAX(2, visibleChildren - numChildren + 2) do begin
      		childTemplate := {_proto: pt_protoDrawnRow};
      		childTemplate:UpdateFromSoup(nil);
      		AddArraySlot(stepChildren, childTemplate);
      	end;
      end,
    viewScrollUpScript:
      func()
      begin
         :SetOrigin(0, MAX(viewOriginY - scrollIncrement, 0));
      end,
    viewScrollDownScript:
      func()
      begin
         :SetOrigin(0, MIN(viewOriginY + scrollIncrement, maxScrollHeight));
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
         :RedoChildren();
      end,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
      	self.stepChildren := nil;
         myCursor := theCursor:Clone();
         :FillCache();
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewSetupDoneScript:
      func()
      begin
      	scrollIncrement := (:LocalBox().bottom DIV viewLineSpacing - 1) * viewLineSpacing;
      end,
    scrollIncrement: nil,
    viewOriginX: 0,
    viewOriginY: 0,
    viewlinespacing: 13,
    maxScrollHeight: nil,
    viewclass: 74,
    debug: "cachedDrawRows"
   };
// View cachedDrawRows is declared to TrueGrid


// ---- Back in File True Grid.t ----

// ---- File SimpleRows.t ----

// Before Script for "simpleRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

simpleRows := /* child of TrueGrid */
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
         local fillCursor := myCursor:Clone();
         for i := 0 to numChildren-1 do begin
            :ChildViewFrames()[i]:UpdateFromSoup(fillCursor:Entry());
            fillCursor:Next();
         end;
      	:Dirty();
      end,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Move(2 - numChildren);
      	if not myCursor:Entry() then myCursor:Next();
      	:FillCache();
      end,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Move(numChildren-2);
      	:FillCache();
      end,
    viewSetupDoneScript:
      func()
      begin
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
      end,
    viewClickScript:
      
      func(unit)
      begin
      
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
         numChildren := :LocalBox().bottom DIV 13 + 1;
         self.stepChildren := Array(numChildren, pt_protoSimpleRow);
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "simpleRows"
   };
// View simpleRows is declared to TrueGrid


// ---- Back in File True Grid.t ----

// ---- File TappedOn.t ----

// Before Script for "tappedOn"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

tappedOn := /* child of TrueGrid */
   {text: "",
    viewBounds: {left: 0, top: 0, right: 160, bottom: 80},
    viewFormat: 83886673,
    viewJustify: 86,
    viewFlags: 2,
    viewEffect: 236577,
    _proto: protoStaticText,
    debug: "tappedOn"
   };
// View tappedOn is declared to TrueGrid


// ---- Back in File True Grid.t ----


// ---- Beginning of non-used User Protos ----

// ---- File protoDrawnRow ----

// Before Script for "protoDrawnRow"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

protoDrawnRow :=
   {viewFlags: 515,
    viewFormat: 305,
    viewBounds: {left: 0, top: 0, right: 220, bottom: 13},
    UpdateFromSoup:
      func(entry)
      begin
         myEntryKey := if entry then entry.aString else nil;
      	shapes := if entry then
      	   [
         	   kLeftTextStyle,
           	   MakeText(entry.aString, 0,0,160,10),
         	   kRightTextStyle,
            	MakeText(SPrintObject(entry.anInteger), 120,0,160,10),
         	   kCenterTextStyle,
            	MakeText(ShortDateStr(entry.aDate, kIncludeAllElements), 160,0,220,10),
            	kBorderStyle,
            	MakeLine(120,0,120,13),
            	MakeLine(160,0,160,13),
         	]
      	else
      		[
            	kBorderStyle,
            	MakeLine(120,0,120,13),
            	MakeLine(160,0,160,13),
      		];
      end,
    viewDrawScript:
      func()
      begin
         :DrawShape(shapes, nil);
      end,
    shapes: nil,
    viewJustify: 8192,
    viewClickScript:
      func(unit)
      begin
      	if :TrackHilite(unit) then
      		:EntrySelected(if myEntryKey then myCursor:GotoKey(myEntryKey) else nil);
      	:Hilite(nil);
      end,
    myEntryKey: nil,
    viewclass: 74,
    debug: "protoDrawnRow"
   };


// ---- File protoSimpleRow ----

// Before Script for "protoSimpleRow"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

protoSimpleRow :=
   {viewFlags: 515,
    viewFormat: 0,
    viewBounds: {left: 0, top: 0, right: 220, bottom: 13},
    UpdateFromSoup:
      func(entry)
      begin
      	if entry then begin
      	   myEntryKey := entry.aString;
      		SetValue(stringView, 'text, entry.aString);
      		SetValue(integerView, 'text, SPrintObject(entry.anInteger));
      		SetValue(dateView, 'text, ShortDateStr(entry.aDate, kIncludeAllElements));
      	end;
      	else begin
      		myEntryKey := nil;
      		SetValue(stringView, 'text, nil);
      		SetValue(integerView, 'text, nil);
      		SetValue(dateView, 'text, nil);
      	end;
      end,
    viewJustify: 8192,
    viewClickScript:
      func(unit)
      begin
      	if :TrackHilite(unit) then
      		:EntrySelected(if myEntryKey then myCursor:GotoKey(myEntryKey) else nil);
      	:Hilite(nil);
      end,
    myEntryKey: nil,
    viewclass: 74,
    debug: "protoSimpleRow"
   };

stringView := /* child of protoSimpleRow */
   {viewFlags: 134217731,
    viewFormat: 305,
    viewFont: ROM_fontSystem9,
    viewBounds: {left: 0, top: 0, right: 120, bottom: 13},
    viewJustify: 8388612,
    viewclass: 81,
    debug: "stringView"
   };
// View stringView is declared to protoSimpleRow



integerView := /* child of protoSimpleRow */
   {viewFlags: 134217731,
    viewFormat: 305,
    viewFont: ROM_fontSystem9,
    viewBounds: {left: 120, top: 0, right: 160, bottom: 13},
    viewJustify: 8388613,
    viewclass: 81,
    debug: "integerView"
   };
// View integerView is declared to protoSimpleRow



dateView := /* child of protoSimpleRow */
   {viewFlags: 134217731,
    viewFormat: 305,
    viewFont: ROM_fontSystem9,
    viewBounds: {left: 160, top: 0, right: 220, bottom: 13},
    viewJustify: 8388614,
    viewclass: 81,
    debug: "dateView"
   };
// View dateView is declared to protoSimpleRow




// ---- End of non-used User Protos ----



// ---- Beginning of section for non used Layout files ----

// ---- File Cached Columns.t ----

// Before Script for "cachedColumns"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

cachedColumns :=
   {viewFlags: 544,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local stringLen := 0;
      	local integerLen := 0;
      	local dateLen := 0;
         local stringCache := SmartStart(128);
         local integerCache :=  SmartStart(128);
      	local dateCache :=  SmartStart(128);
      
         local f := func(entry)
            begin
      			stringLen := SmartConcat(stringCache, stringLen, entry.aString);
      			stringLen := SmartConcat(stringCache, stringLen, $\n);
      			integerLen := SmartConcat(integerCache, integerLen, SPrintObject(entry.anInteger));
      			integerLen := SmartConcat(integerCache, integerLen, $\n);
      			dateLen := SmartConcat(dateCache, dateLen, ShortDateStr(entry.aDate, kIncludeAllElements));
      			dateLen := SmartConcat(dateCache, dateLen, $\n);
      			entry.aString;
            end;
      
         myCursor:Reset();
         keyArray := MapCursor(myCursor, f);
         SmartStop(stringCache, stringLen);
         SmartStop(integerCache, integerLen);
         SmartStop(dateCache, dateLen);
         SetValue(stringCol, 'text, stringCache);
         SetValue(integerCol, 'text, integerCache);
         SetValue(dateCol, 'text, dateCache);
      end,
    keyArray: nil,
    viewOriginY: 0,
    viewScrollUpScript:
      func()
      begin
         :SetOrigin(0, MAX(viewOriginY - scrollIncrement, 0));
      end,
    viewScrollDownScript:
      func()
      begin
         :SetOrigin(0, viewOriginY + scrollIncrement);
      end,
    viewlinespacing: 13,
    viewSetupDoneScript:
      func()
      begin
      	scrollIncrement := (:LocalBox().bottom DIV viewLineSpacing - 1) * viewLineSpacing;
         :SetOrigin(0,0);
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         :SetOrigin(0,0);
         :FillCache();
      end,
    viewClickScript:
      func(unit)
      begin
         InkOff(unit);
         PlaySound(ROM_click);
         local box := :LocalBox();
         local row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         local oldRow := row;
         local t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
         :DoDrawing('DrawShape, [t, kXORstyle]);
         repeat
            row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
            if row <> oldRow then begin
               PlaySound(ROM_click);
               :DoDrawing('DrawShape, [t, kXORstyle]);
               t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
               :DoDrawing('DrawShape, [t, kXORstyle]);
               oldRow := row;
            end;
            sleep(1);
         until StrokeDone(unit);
       
         row := (GetPoint(finalY, unit) - :GlobalBox().top + viewOriginY) div viewLineSpacing;
         if row < length(keyArray) then 
            :EntrySelected(myCursor:GotoKey(keyArray[row]));
         else
            :EntrySelected(nil);
         :DoDrawing('DrawShape, [t, kXORstyle]);
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    myCursor: nil,
    scrollIncrement: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "cachedColumns"
   };

stringCol := /* child of cachedColumns */
   {viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {left: 0, top: 0, right: 300, bottom: 1000},
    viewFlags: 134217731,
    viewlinespacing: 13,
    viewclass: 81,
    debug: "stringCol"
   };
// View stringCol is declared to cachedColumns



dateCol := /* child of cachedColumns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewBounds: {top: 0, left: -60, right: 0, bottom: 1000},
    viewFont: ROM_fontSystem9;,
    viewlinespacing: 13,
    viewJustify: 34,
    viewclass: 81,
    debug: "dateCol"
   };
// View dateCol is declared to cachedColumns



integerCol := /* child of cachedColumns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {top: 0, left: -40, right: 0, bottom: 1000},
    viewlinespacing: 13
    ,
    viewJustify: 2049,
    viewclass: 81,
    debug: "integerCol"
   };
// View integerCol is declared to cachedColumns




// ---- File Cached Draw Rows.t ----

// Before Script for "cachedDrawRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

cachedDrawRows :=
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local childTemplate;
      	local visibleChildren := :LocalBox().bottom DIV viewLineSpacing + 1;
      	
         local f := func(entry)
            begin
            	childTemplate := {_proto: pt_protoDrawnRow};
            	childTemplate:UpdateFromSoup(entry);
            	AddArraySlot(stepChildren, childTemplate); 
      			entry.aString;
            end;
      	
      	stepChildren := [];
      	myCursor:Reset();
      	keyArray := MapCursor(myCursor, f);
      	numChildren := length(keyArray);
      	maxScrollHeight := MAX(0, numChildren - visibleChildren + 2) * viewLineSpacing;
      	for i := 0 to MAX(2, visibleChildren - numChildren + 2) do begin
      		childTemplate := {_proto: pt_protoDrawnRow};
      		childTemplate:UpdateFromSoup(nil);
      		AddArraySlot(stepChildren, childTemplate);
      	end;
      end,
    viewScrollUpScript:
      func()
      begin
         :SetOrigin(0, MAX(viewOriginY - scrollIncrement, 0));
      end,
    viewScrollDownScript:
      func()
      begin
         :SetOrigin(0, MIN(viewOriginY + scrollIncrement, maxScrollHeight));
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
         :RedoChildren();
      end,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
      	self.stepChildren := nil;
         myCursor := theCursor:Clone();
         :FillCache();
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewSetupDoneScript:
      func()
      begin
      	scrollIncrement := (:LocalBox().bottom DIV viewLineSpacing - 1) * viewLineSpacing;
      end,
    scrollIncrement: nil,
    viewOriginX: 0,
    viewOriginY: 0,
    viewlinespacing: 13,
    maxScrollHeight: nil,
    viewclass: 74,
    debug: "cachedDrawRows"
   };


// ---- File Columns.t ----

// Before Script for "columns"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

columns :=
   {myCursor: nil,
    viewSetupDoneScript:
      func()
      begin
      	visibleRows := :LocalBox().bottom DIV viewLineSpacing + 1;
      	myCursor := theCursor:Clone();
      	myCursor:Reset();
      	topEntry := myCursor:Entry();
         :FillCache();
      end,
    viewFormat: 337,
    viewlinespacing: 13,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    integerCache: nil,
    stringCache: nil,
    viewFlags: 544,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
      	local stringLen := 0;
      	local integerLen := 0;
      	local dateLen := 0;
         local stringCache := SmartStart(128);
         local integerCache :=  SmartStart(128);
      	local dateCache :=  SmartStart(128);
      	local entry := topEntry;
      
      	keyArray := Array(visibleRows, nil);
         if entry then
      	   begin
      		   myCursor:Goto(topEntry);
      		   for i := 0 to visibleRows-1 do
      		      begin
      					stringLen := SmartConcat(stringCache, stringLen, entry.aString);
      					stringLen := SmartConcat(stringCache, stringLen, $\n);
      					integerLen := SmartConcat(integerCache, integerLen, SPrintObject(entry.anInteger));
      					integerLen := SmartConcat(integerCache, integerLen, $\n);
      					dateLen := SmartConcat(dateCache, dateLen, ShortDateStr(entry.aDate, kIncludeAllElements));
      					dateLen := SmartConcat(dateCache, dateLen, $\n);
      					keyArray[i] := entry.aString;
      					if not entry := myCursor:Next() then begin
      						SetLength(keyArray, i+1);
      						break;
      					end;
      				end;
      		end;
      	else
      		SetLength(keyArray, 0) ;
      		
         SmartStop(stringCache, stringLen);
         SmartStop(integerCache, integerLen);
         SmartStop(dateCache, dateLen);
         SetValue(stringCol, 'text, stringCache);
         SetValue(integerCol, 'text, integerCache);
         SetValue(dateCol, 'text, dateCache);
      end,
    viewOriginY: 0,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Goto(topEntry);
      	if not topEntry := myCursor:Move(visibleRows - 2) then
      		if not topEntry := myCursor:Move(2 - visibleRows) then
      			topEntry := myCursor:Next();
      	:fillCache();
      end,
    viewJustify: 208,
    topEntry: nil,
    visibleRows: nil,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Goto(topEntry);
      	if not topEntry := myCursor:Move(2 - visibleRows) then
      		topEntry := myCursor:Next();
      	:fillCache();
      end,
    keyArray: nil,
    viewClickScript:
      func(unit)
      begin
         InkOff(unit);
         PlaySound(ROM_click);
         local box := :LocalBox();
         local row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         local theRow := row;
         local inside := true;
         local t := MakeRect(0, row * viewLineSpacing, box.right, (row+1) * viewLineSpacing);
         :DoDrawing('DrawShape, [t, kXORstyle]);
         repeat
            row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
            if inside and row <> theRow then begin
               :DoDrawing('DrawShape, [t, kXORstyle]);
               inside := nil;
            end;
      		else if not inside and row = theRow then begin
      			:DoDrawing('DrawShape, [t, kXORstyle]);
      			inside := true;
      		end;	
            sleep(1);
         until StrokeDone(unit);
       
         row := (GetPoint(finalY, unit) - :GlobalBox().top) div viewLineSpacing;
         if row = theRow and row < length(keyArray) then 
            :EntrySelected(myCursor:GotoKey(keyArray[row]));
         else
            :EntrySelected(nil);
         if inside then
         	begin	// simply XOring the rectangle again won't work, :EntrySelected() changes drawing.
         		:Dirty();
         		RefreshViews();
         	end
      end;,
    viewclass: 74,
    debug: "columns",
    dateCache: nil,
    soupChanged:
      func(theSoupName)
      	if StrEqual(theSoupName, kSoupName) then begin
      		topEntry := myCursor:Reset();
      	   :FillCache();
      end
   };

stringCol := /* child of columns */
   {viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {left: 0, top: 0, right: 300, bottom: 1000},
    viewFlags: 134217731,
    viewlinespacing: 13,
    viewclass: 81,
    debug: "stringCol"
   };
// View stringCol is declared to columns



dateCol := /* child of columns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewBounds: {top: 0, left: -60, right: 0, bottom: 1000},
    viewFont: ROM_fontSystem9;,
    viewlinespacing: 13,
    viewJustify: 34,
    viewclass: 81,
    debug: "dateCol"
   };
// View dateCol is declared to columns



integerCol := /* child of columns */
   {viewFlags: 134217731,
    viewFormat: 12593,
    viewFont: ROM_fontSystem9;,
    viewBounds: {top: 0, left: -40, right: 0, bottom: 1000},
    viewlinespacing: 13
    ,
    viewJustify: 2049,
    viewclass: 81,
    debug: "integerCol"
   };
// View integerCol is declared to columns




// ---- File Draw Rows.t ----

// Before Script for "drawRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

drawRows :=
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
         local fillCursor := myCursor:Clone();
         for i := 0 to numChildren-1 do begin
            :ChildViewFrames()[i]:UpdateFromSoup(fillCursor:Entry());
            fillCursor:Next();
         end;
      	:Dirty();
      end,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Move(2 - numChildren);
      	if not myCursor:Entry() then myCursor:Next();
      	:FillCache();
      end,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Move(numChildren-2);
      	:FillCache();
      end,
    viewSetupDoneScript:
      func()
      begin
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
      end,
    viewClickScript:
      
      func(unit)
      begin
      
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
         numChildren := :LocalBox().bottom DIV 13 + 1;
         self.stepChildren := Array(numChildren, pt_protoDrawnRow);
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "drawRows"
   };


// ---- File SimpleRows.t ----

// Before Script for "simpleRows"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

simpleRows :=
   {viewFlags: 32,
    viewFormat: 337,
    viewBounds: {top: 60, left: 0, right: 220, bottom: -22},
    fillCache:
      func()
      begin
         local fillCursor := myCursor:Clone();
         for i := 0 to numChildren-1 do begin
            :ChildViewFrames()[i]:UpdateFromSoup(fillCursor:Entry());
            fillCursor:Next();
         end;
      	:Dirty();
      end,
    viewScrollUpScript:
      func()
      begin
      	myCursor:Move(2 - numChildren);
      	if not myCursor:Entry() then myCursor:Next();
      	:FillCache();
      end,
    viewScrollDownScript:
      func()
      begin
      	myCursor:Move(numChildren-2);
      	:FillCache();
      end,
    viewSetupDoneScript:
      func()
      begin
         myCursor := theCursor:Clone();
         myCursor:Reset();
         :FillCache();
      end,
    soupChanged:
      func(theSoupName)
      if StrEqual(theSoupName, kSoupName) then begin
         myCursor:Reset();
         :FillCache();
      end,
    viewClickScript:
      
      func(unit)
      begin
      
      end;,
    viewQuitScript:
      func()
      begin
         keyArray := nil;
         stringCache := nil;
         dateCache := nil;
         integerCache := nil;
         myCursor := nil;
      end,
    viewSetupChildrenScript:
      func()
      begin
         numChildren := :LocalBox().bottom DIV 13 + 1;
         self.stepChildren := Array(numChildren, pt_protoSimpleRow);
      end,
    numChildren: nil,
    myCursor: nil,
    viewJustify: 208,
    viewclass: 74,
    debug: "simpleRows"
   };


// ---- File TappedOn.t ----

// Before Script for "tappedOn"
// Copyright © 1994 by Apple Computer, Inc.  All rights reserved.

tappedOn :=
   {text: "",
    viewBounds: {left: 0, top: 0, right: 160, bottom: 80},
    viewFormat: 83886673,
    viewJustify: 86,
    viewFlags: 2,
    viewEffect: 236577,
    _proto: protoStaticText,
    debug: "tappedOn"
   };


// End of output